﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace PSE.Framework.UI.Controls.SmartClient
{
    public class TreeView : System.Windows.Controls.TreeView
    {
        BufferedEventManager<RoutedEventArgs> _bufferedEventManager;

        public TreeView()
        {
            _bufferedEventManager = new BufferedEventManager<RoutedEventArgs>();
            this.SelectedItemChanged += _bufferedEventManager.EventCapturer;
            _bufferedEventManager.AddBufferedEventListener(this, BufferedSelectedItemChangedListener);

            this.Loaded += new System.Windows.RoutedEventHandler(TreeView_Loaded);
            this.Unloaded += new System.Windows.RoutedEventHandler(TreeView_Unloaded);
        }

        void TreeView_Unloaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _bufferedEventManager.Stop();
        }

        void TreeView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            _bufferedEventManager.Start();
        }

        public delegate void BufferedSelectedItemChangedHandler(object sender, RoutedEventArgs e, int clickCount);
        public event BufferedSelectedItemChangedHandler BufferedSelectedItemChanged;

        private void BufferedSelectedItemChangedListener(object sender, RoutedEventArgs e, int clickCount)
        {
            if (BufferedSelectedItemChanged != null)
                BufferedSelectedItemChanged(sender, e, clickCount);
        }
    }

    public class TreeViewItem : System.Windows.Controls.TreeViewItem
    {
    }
}
